home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1999 June / macpower199906.bin / 9906⁄AMUG / INTERNET / NetCacheResolver 0.9d7.sit / NetCacheResolver 0.9d7 folder / source code CWPro4 / source / main.c next >
Encoding:
Text File  |  1999-02-04  |  3.0 KB  |  154 lines  |  [TEXT/CWIE]

  1. // NetCache Resolver, 1995 (C) Mizutori Tetsuya
  2. // - main.c, October 8, 1995
  3. // This document is pretty printed in 10-point Geneva font.
  4.  
  5. //#define DEBUG 1
  6.  
  7. #include "NCR_Basic.h"
  8. #include "NCR_Resolve.h"
  9. #include "NCR_AppleEvent.h"
  10. #include "NCR_Event.h"
  11. #include "NCR_FIle.h"
  12. #include "NCR_Qsort.h"
  13. #include "NCR_Error.h"
  14.  
  15. #ifdef DEBUG
  16. #include "NCR_Message.h"
  17. #endif /* DEBUG */
  18.  
  19. // definitions
  20.  
  21. // prototype
  22. /***** main *****/
  23. void main ( void );
  24.  
  25. /***** callback for MenuChoice *****/
  26. OSErr DoOpen ( WindowPtr window );
  27.  
  28. /***** callback for AppleEvent *****/
  29. OSErr DoOpenApplication ( void );
  30. OSErr DoQuitApplication ( void );
  31. OSErr DoPrintDocument ( void );
  32. OSErr DoOpenDocument ( FSSpec *theFSSpec, long index, long count );
  33.  
  34. /***** Do Operation *****/
  35. OSErr DoOperation ( FSSpec *theFSSpec );
  36.  
  37. /***** main *****/
  38. void main ( void )
  39. {
  40.     ToolboxInit();
  41.     SetupAppleEvent();
  42.     
  43. #ifdef DEBUG
  44.     NewMessage();
  45. //    MessageTest();
  46. //    DoOpen( (WindowPtr) nil );
  47. #endif /* DEBUG */
  48.  
  49.     EventLoop();
  50.     
  51.     ExitToShell();
  52. }
  53.  
  54.  
  55. /***** callback for MenuChoice *****/
  56. OSErr DoOpen ( WindowPtr window )
  57. {
  58.     FSSpec     theFSSpec;
  59.     short        numTypes = 1; //-1 for all types;
  60.     OSType    typeList[] = {'DBMC', 'TEXT', 0, 0};
  61.     OSErr    err;
  62.     
  63.     if ( ! GetFilename( &theFSSpec, numTypes, typeList ) ) return paramErr;
  64.     
  65.     err = DoOperation( &theFSSpec );
  66.     
  67.     return err;
  68. }
  69.  
  70.  
  71. /***** callback for AppleEvent *****/
  72. OSErr DoOpenApplication ( void )
  73. {
  74.     OSErr    err = noErr;
  75.     
  76.     SetupMenuBar();
  77.     
  78. //    err = DoOpen( (WindowPtr) nil );
  79.  
  80.     return err;
  81. }
  82.  
  83. OSErr DoQuitApplication ( void )
  84. {
  85.     // do nothing, here
  86.     
  87.     return noErr;
  88. }
  89.  
  90. OSErr DoPrintDocument ( void )
  91. {
  92.     // do nothing, here.
  93.     
  94.     return noErr;
  95. }
  96.  
  97. OSErr DoOpenDocument ( FSSpec *theFSSpec, long index, long count )
  98. {
  99.     OSErr    err;
  100.     
  101.     err = DoOperation( theFSSpec );
  102.     
  103.     return err;
  104. }
  105.  
  106. /***** Do Operation *****/
  107. OSErr DoOperation ( FSSpec *theFSSpec )
  108. {
  109.     FSSpec     theFSSpec2;
  110.     FInfo        theFInfo, theFInfo2;
  111.     Handle    theHndl = nil;
  112.     long        datasize;
  113.     Str63    cacheLog;                // read from 'STR#'
  114.     Str31    strFdType;
  115.     OSType    fdType = 'TEXT';            // read from 'STR#'
  116.     OSErr    err = noErr;
  117.  
  118.     GetIndString( cacheLog, STRID_CACHE, STRIX_CACHE );
  119.     GetIndString( strFdType, STRID_CACHE, STRIX_CACHETYPE );
  120.     BlockMove( &strFdType[1], &fdType, 4 );
  121.     
  122.     theHndl = NewHandleClear( 0 );        // create a Handle 'theHndl'
  123.     if ( (err=MemError()) != noErr ) { ErrorMessageMEM( err, true ); }
  124.  
  125.     err = GetRecordFromFile( theFSSpec, &theFInfo, theHndl, &datasize );
  126.     if ( err != noErr ) { ErrorMessageFS( err, false ); goto out; }
  127.  
  128.     theFInfo2 = theFInfo;
  129.     theFInfo2.fdType = fdType;
  130.  
  131.     theFSSpec2 = *theFSSpec;
  132.     BlockMove( cacheLog, theFSSpec2.name, cacheLog[0]+1);
  133.  
  134. #ifdef COMMENT
  135.     do {
  136.         long        fileID;
  137.         FSSpec     theFSSpec3;
  138.         
  139.         theFSSpec3 = theFSSpec2;
  140.         GenFilename( theFSSpec2.name, theFSSpec3.name );
  141.     } while ( QueryFile( &theFSSpec2, &fileID ) );
  142. #endif /* COMMENT */
  143.  
  144.     err = WriteFile( &theFSSpec2, &theFInfo2, theHndl, &datasize );
  145.     if ( err != noErr ) { ErrorMessageFS( err, false ); goto out; }
  146.  
  147.   out:
  148.     if ( theHndl != nil ) DisposeHandle( theHndl );    // dispose the Handle 'theHndl'
  149.  
  150.     return err;
  151. }
  152.  
  153. // end of program
  154.